<script language="javascript" type="text/javascript" src="<?php echo $this->getSkinUrl()?>js/faq_smooth.js"></script>
<?php
	function subwords($words,$num){

	$total_num = str_word_count($words); 

	if($total_num <= $num){  
		return $words;
	}else{
		$pattern = '/([\S]+?[ ]+){'.$num.'}/';
		preg_match($pattern, $words, $out);
		return $out[0].'...'; 
	}
}
?>
<?php 
    $timetables = Mage::getModel('timetables/cat')->getCollection();
    $timetables->load();
?>

<div class="calculator">
  <div class="border1"><img src="http://autotrail.panbx.com/skin/frontend/default/autotrail/images/border3.png"></div>
  <div class="c_box">
    <div class="timetables_p">
      <div class="title_long">
        <div class="border1"><img alt="" src="http://autotrail.panbx.com/skin/frontend/default/autotrail/images/border6.png"></div>
        <div class="title_c"><span>FREQUENTLY ASKED QUESTIONS</span></div>
        <div class="border1"><img alt="" src="http://autotrail.panbx.com/skin/frontend/default/autotrail/images/border6.png"></div>
      </div>
      <div style="margin-top: 10px;">
        <div class="list_title">
          <div class="div_border_287"></div>
          <div class="box_f">
          <?php foreach ($timetables as $faq): ?>
            <ul>
              <li><a href="#"><?php echo $faq->getTitle();?></a></li>
          <?php $posts = Mage::getModel('timetables/post')->getCollection();
                $posts->addFieldToFilter('cat_id', $faq->getCatId());
                $posts->load();
           ?>
                <?php foreach($posts as $post):?>
                    <li><a onclick="scroller('<?php echo $post->getTitle()?>',1, 800); change_class('list_num',<?php echo $post->getPostId(); ?>)"><?php echo $post->getTitle();?></a></li>
                <?php endforeach;?>
                </ul>
           <?php endforeach;?>
          </div>
          <div class="div_border_287"></div>
          <div style="margin-top:5px;"><a href="<?php echo $this->getUrl();?>contacts"><img src="<?php echo $this->getSkinUrl();?>images/img_contact.png"/></a></div>
        </div>
        <div class="list_wraper">
         <?php foreach ($timetables as $faq): ?>
        <div class="list_content">
          <div class="list_box">
            <div class="title">
              <div class="div_border_640"></div>
              <div class="ca_name"><span><?php echo $faq->getTitle();?></span></div>
              <?php $posts = Mage::getModel('timetables/post')->getCollection();
                $posts->addFieldToFilter('cat_id', $faq->getCatId());
                $posts->load();
              ?>
            </div>
          </div>
            
            <div class="list_co">
                <?php foreach($posts as $post):?>
          <a id="<?php echo $post->getTitle();?>"></a>          
            <div id="list_num<?php echo $post->getPostId();?>" class="list_ca">
              <div class="div_border_630"></div>
              <div class="main">
                <div class="t"><?php echo $post->getTitle();?></div>
                <div class="des"><?php echo $post->getPostContent();?></div>
              </div>
              <div class="div_border_630"></div>
            </div>
            <?php endforeach;?>
          </div>
        </div>
        <?php endforeach;?>
        </div>
        <div class="clearfloat"></div>
      </div>
    </div>
  </div>
  <div class="border1"><img src="http://autotrail.panbx.com/skin/frontend/default/autotrail/images/border3.png"></div>
</div>
